package data;

import java.io.IOException;

import network.e2e.FrameReader;
import network.e2e.FrameWriter;

/**
 * Parser from the net that can retrieve or send a corresponding object
 */

public class DataParser {
  
  /**
   * Decode a data from the network
   * @requires reader not null
   * @param reader the net
   * @return the data read
   * @throws IOException 
   */
  public static Data retrieve(FrameReader reader) throws IOException {
    assert (reader != null);
    return new Data(reader);
  }
  
  /**
   * Encode a data to be sent over the network
   * @requires param not null
   * @param data the data
   * @param writer  the net
   * @throws IOException 
   */
  public static void send(Data data, FrameWriter writer) throws IOException {
    assert data != null && writer != null;
    data.send(writer);
  }
  
}
